package com.tjtt.gwm.action;

import java.io.File;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.apache.struts2.ServletActionContext;

import com.tjtt.gwm.service.DbService;
import com.tjtt.gwm.service.TongjiService;
import com.tjtt.tdm.base.BaseAction;
import com.tjtt.tdm.base.PageResult;
import com.tjtt.tdm.base.PubMethod;
import com.tjtt.tdm.util.ExcelTool;
import com.tjtt.tdm.util.StringUtil;

public class TongjiAction extends BaseAction {
	private TongjiService tongjiService;
	private DbService dbService;
	public TongjiService getTongjiService() {
		return tongjiService;
	}
	public void setTongjiService(TongjiService tongjiService) {
		this.tongjiService = tongjiService;
	}
	public DbService getDbService() {
		return dbService;
	}
	public void setDbService(DbService dbService) {
		this.dbService = dbService;
	}
	
	public void tongjiJingtaisj(){
		try{
			String fieldname = getRequest().getParameter("fieldname");
			String gxids = getRequest().getParameter("gxids");
			Map<String,String> filterMap=getPagerMap();
			if(null!=fieldname && !"".equals(fieldname)){
				filterMap.put("fieldname", fieldname);
			}
			if(null!=gxids && !"".equals(gxids)){
				filterMap.put("gxids", gxids);
			}
			PageResult result= tongjiService.tongjiJingtaisj(filterMap);
			String[] viewArray={"tongjixm","guanxianbh","heji"};
			String str=getColumnJson(result,viewArray);
			HttpServletResponse response = ServletActionContext.getResponse();
			response.setContentType("application/XML,charset=GBK");
			response.setHeader("Charset", "GBK");
			response.setCharacterEncoding("GBK");
			response.setContentType("text/xml");
			PrintWriter out = getResponse().getWriter();
			out.print(str);
			}
			catch (Exception e) {
				e.printStackTrace();
			}
	}
	
	public void tongjiJingtaisjpic(){
		try{
			String fieldname = getRequest().getParameter("fieldname");
			String gxids = getRequest().getParameter("gxids");
			Map<String,String> filterMap=getPagerMap();
			if(null!=fieldname && !"".equals(fieldname)){
				filterMap.put("fieldname", fieldname);
			}
			if(null!=gxids && !"".equals(gxids)){
				filterMap.put("gxids", gxids);
			}
			List lists = tongjiService.tongjiJingtaisjpic(filterMap);
			JSONObject root = new JSONObject();
			JSONArray jsonArray = new JSONArray();
			List<String> strList = new ArrayList<String>();
			for(int i=0;i<lists.size();i++){
				Object[] objs = (Object[])lists.get(i);
				JSONObject obsjson = new JSONObject();
				String labelname = objs[0]==null?"":objs[0].toString();
				obsjson.put("name", labelname);
				obsjson.put("value", objs[2]==null?"":objs[2].toString());
				jsonArray.add(obsjson);
				strList.add(labelname);
			}
			root.put("list", jsonArray);
			root.put("label", strList);
			PrintWriter out = com.tjtt.tdm.base.PubMethod.GetPrintWriter();
			out.print(root);
			}
			catch (Exception e) {
				e.printStackTrace();
			}
	}
	
	public void tongjiJingtaisjexp(){
		try{
			String fieldname = getRequest().getParameter("fieldname");
			String gxids = getRequest().getParameter("gxids");
			Map<String,String> filterMap=getPagerMap();
			if(null!=fieldname && !"".equals(fieldname)){
				filterMap.put("fieldname", fieldname);
			}
			if(null!=gxids && !"".equals(gxids)){
				filterMap.put("gxids", gxids);
			}
			List lists = tongjiService.tongjiJingtaisjpic(filterMap);
			String filename = PubMethod.GetTimerName();
			String fileName=filename+".xlsx";			
			String pathUrl = getRequest().getSession().getServletContext().getRealPath("");
			String sourcefilepath = pathUrl+"\\tongji\\expmode.xlsx";
			String targetfilepath = pathUrl+"\\tongji\\temp\\"+fileName;
			File targetfile = new File(targetfilepath);
			if (targetfile.exists()){
				targetfile.deleteOnExit();
			} 
			PubMethod.copyFile(new File(sourcefilepath), new File(targetfilepath));
			ExcelTool et = new ExcelTool(targetfilepath);
			int listsize = lists.size();
			et.InsertRowsAndCopy(1, 2, listsize-1);
			for(int i=0;i<listsize;i++){
				Object[] objs = (Object[])lists.get(i);
				et.SetCells(i+2, 1, objs[0].toString());
				et.SetCells(i+2, 2, objs[1].toString());
				et.SetCells(i+2, 3, objs[2].toString());
			}
			et.Save();
			PubMethod.exportFile(targetfilepath,getResponse());
			targetfile = new File(targetfilepath);
			if (targetfile.exists()){
				targetfile.deleteOnExit();
			} 
		}
		catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public void tongjiYalijz(){
		try{
			String fieldname = getRequest().getParameter("fieldname");
			String gxids = getRequest().getParameter("gxids");
			String zxids = getRequest().getParameter("zxids");
			String fmids = getRequest().getParameter("fmids");
			Map<String,String> filterMap=getPagerMap();
			if(null!=fieldname && !"".equals(fieldname)){
				filterMap.put("fieldname", fieldname);
			}
			if(null!=gxids && !"".equals(gxids)){
				filterMap.put("gxids", gxids);
			}
			if(null!=zxids && !"".equals(zxids)){
				filterMap.put("zxids", zxids);
			}
			if(null!=fmids && !"".equals(fmids)){
				filterMap.put("fmids", fmids);
			}
			PageResult result= tongjiService.tongjiYalijz(filterMap);
			String[] viewArray={"tongjixm","guanxianbh","heji"};
			String str=getColumnJson(result,viewArray);
			HttpServletResponse response = ServletActionContext.getResponse();
			response.setContentType("application/XML,charset=GBK");
			response.setHeader("Charset", "GBK");
			response.setCharacterEncoding("GBK");
			response.setContentType("text/xml");
			PrintWriter out = getResponse().getWriter();
			out.print(str);
			}
			catch (Exception e) {
				e.printStackTrace();
			}
	}
	
	public void tongjiYalijzpic(){
		try{
			String fieldname = getRequest().getParameter("fieldname");
			String gxids = getRequest().getParameter("gxids");
			String zxids = getRequest().getParameter("zxids");
			String fmids = getRequest().getParameter("fmids");
			Map<String,String> filterMap=getPagerMap();
			if(null!=fieldname && !"".equals(fieldname)){
				filterMap.put("fieldname", fieldname);
			}
			if(null!=gxids && !"".equals(gxids)){
				filterMap.put("gxids", gxids);
			}
			if(null!=zxids && !"".equals(zxids)){
				filterMap.put("zxids", zxids);
			}
			if(null!=fmids && !"".equals(fmids)){
				filterMap.put("fmids", fmids);
			}
			List lists = tongjiService.tongjiYalijzpic(filterMap);
			JSONObject root = new JSONObject();
			JSONArray jsonArray = new JSONArray();
			List<String> strList = new ArrayList<String>();
			for(int i=0;i<lists.size();i++){
				Object[] objs = (Object[])lists.get(i);
				JSONObject obsjson = new JSONObject();
				String labelname = objs[0]==null?"":objs[0].toString();
				obsjson.put("name", labelname);
				obsjson.put("value", objs[2]==null?"":objs[2].toString());
				jsonArray.add(obsjson);
				strList.add(labelname);
			}
			root.put("list", jsonArray);
			root.put("label", strList);
			PrintWriter out = com.tjtt.tdm.base.PubMethod.GetPrintWriter();
			out.print(root);
			}
			catch (Exception e) {
				e.printStackTrace();
			}
	}
	
	public void tongjiYalijzexp(){
		try{
			String fieldname = getRequest().getParameter("fieldname");
			String gxids = getRequest().getParameter("gxids");
			String zxids = getRequest().getParameter("zxids");
			String fmids = getRequest().getParameter("fmids");
			Map<String,String> filterMap=getPagerMap();
			if(null!=fieldname && !"".equals(fieldname)){
				filterMap.put("fieldname", fieldname);
			}
			if(null!=gxids && !"".equals(gxids)){
				filterMap.put("gxids", gxids);
			}
			if(null!=zxids && !"".equals(zxids)){
				filterMap.put("zxids", zxids);
			}
			if(null!=fmids && !"".equals(fmids)){
				filterMap.put("fmids", fmids);
			}
			List lists = tongjiService.tongjiYalijzpic(filterMap);
			JSONObject root = new JSONObject();
			JSONArray jsonArray = new JSONArray();
			List<String> strList = new ArrayList<String>();
			String filename = PubMethod.GetTimerName();
			String fileName=filename+".xlsx";			
			String pathUrl = getRequest().getSession().getServletContext().getRealPath("");
			String sourcefilepath = pathUrl+"\\tongji\\expmode.xlsx";
			String targetfilepath = pathUrl+"\\tongji\\temp\\"+fileName;
			File targetfile = new File(targetfilepath);
			if (targetfile.exists()){
				targetfile.deleteOnExit();
			} 
			PubMethod.copyFile(new File(sourcefilepath), new File(targetfilepath));
			ExcelTool et = new ExcelTool(targetfilepath);
			int listsize = lists.size();
			et.InsertRowsAndCopy(1, 2, listsize-1);
			for(int i=0;i<listsize;i++){
				Object[] objs = (Object[])lists.get(i);
				et.SetCells(i+2, 1, objs[0].toString());
				et.SetCells(i+2, 2, objs[1].toString());
				et.SetCells(i+2, 3, objs[2].toString());
			}
			et.Save();
			PubMethod.exportFile(targetfilepath,getResponse());
			targetfile = new File(targetfilepath);
			if (targetfile.exists()){
				targetfile.deleteOnExit();
			} 
		}
		catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public void tongjiYunxingdw(){
		try{
			String fieldname = getRequest().getParameter("fieldname");
			String gxids = getRequest().getParameter("gxids");
			String zxids = getRequest().getParameter("zxids");
			String fmids = getRequest().getParameter("fmids");
			Map<String,String> filterMap=getPagerMap();
			if(null!=fieldname && !"".equals(fieldname)){
				filterMap.put("fieldname", fieldname);
			}
			if(null!=gxids && !"".equals(gxids)){
				filterMap.put("gxids", gxids);
			}
			if(null!=zxids && !"".equals(zxids)){
				filterMap.put("zxids", zxids);
			}
			if(null!=fmids && !"".equals(fmids)){
				filterMap.put("fmids", fmids);
			}
			PageResult result= tongjiService.tongjiYunxingdw(filterMap);
			String[] viewArray={"tongjixm","guanxianbh","heji"};
			String str=getColumnJson(result,viewArray);
			HttpServletResponse response = ServletActionContext.getResponse();
			response.setContentType("application/XML,charset=GBK");
			response.setHeader("Charset", "GBK");
			response.setCharacterEncoding("GBK");
			response.setContentType("text/xml");
			PrintWriter out = getResponse().getWriter();
			out.print(str);
			}
			catch (Exception e) {
				e.printStackTrace();
			}
	}
	
	public void tongjiYunxingdwpic(){
		try{
			String fieldname = getRequest().getParameter("fieldname");
			String gxids = getRequest().getParameter("gxids");
			String zxids = getRequest().getParameter("zxids");
			String fmids = getRequest().getParameter("fmids");
			Map<String,String> filterMap=getPagerMap();
			if(null!=fieldname && !"".equals(fieldname)){
				filterMap.put("fieldname", fieldname);
			}
			if(null!=gxids && !"".equals(gxids)){
				filterMap.put("gxids", gxids);
			}
			if(null!=zxids && !"".equals(zxids)){
				filterMap.put("zxids", zxids);
			}
			if(null!=fmids && !"".equals(fmids)){
				filterMap.put("fmids", fmids);
			}
			List lists = tongjiService.tongjiYunxingdwpic(filterMap);
			JSONObject root = new JSONObject();
			JSONArray jsonArray = new JSONArray();
			List<String> strList = new ArrayList<String>();
			for(int i=0;i<lists.size();i++){
				Object[] objs = (Object[])lists.get(i);
				JSONObject obsjson = new JSONObject();
				String labelname = objs[0]==null?"":objs[0].toString();
				obsjson.put("name", labelname);
				obsjson.put("value", objs[2]==null?"":objs[2].toString());
				jsonArray.add(obsjson);
				strList.add(labelname);
			}
			root.put("list", jsonArray);
			root.put("label", strList);
			PrintWriter out = com.tjtt.tdm.base.PubMethod.GetPrintWriter();
			out.print(root);
			}
			catch (Exception e) {
				e.printStackTrace();
			}
	}
	
	public void tongjiYunxingdwexp(){
		try{
			String fieldname = getRequest().getParameter("fieldname");
			String gxids = getRequest().getParameter("gxids");
			String zxids = getRequest().getParameter("zxids");
			String fmids = getRequest().getParameter("fmids");
			Map<String,String> filterMap=getPagerMap();
			if(null!=fieldname && !"".equals(fieldname)){
				filterMap.put("fieldname", fieldname);
			}
			if(null!=gxids && !"".equals(gxids)){
				filterMap.put("gxids", gxids);
			}
			if(null!=zxids && !"".equals(zxids)){
				filterMap.put("zxids", zxids);
			}
			if(null!=fmids && !"".equals(fmids)){
				filterMap.put("fmids", fmids);
			}
			List lists = tongjiService.tongjiYunxingdwpic(filterMap);
			String filename = PubMethod.GetTimerName();
			String fileName=filename+".xlsx";			
			String pathUrl = getRequest().getSession().getServletContext().getRealPath("");
			String sourcefilepath = pathUrl+"\\tongji\\expmode.xlsx";
			String targetfilepath = pathUrl+"\\tongji\\temp\\"+fileName;
			File targetfile = new File(targetfilepath);
			if (targetfile.exists()){
				targetfile.deleteOnExit();
			} 
			PubMethod.copyFile(new File(sourcefilepath), new File(targetfilepath));
			ExcelTool et = new ExcelTool(targetfilepath);
			int listsize = lists.size();
			et.InsertRowsAndCopy(1, 2, listsize-1);
			for(int i=0;i<listsize;i++){
				Object[] objs = (Object[])lists.get(i);
				et.SetCells(i+2, 1, objs[0].toString());
				et.SetCells(i+2, 2, objs[1].toString());
				et.SetCells(i+2, 3, objs[2].toString());
			}
			et.Save();
			PubMethod.exportFile(targetfilepath,getResponse());
			targetfile = new File(targetfilepath);
			if (targetfile.exists()){
				targetfile.deleteOnExit();
			} 
		}
		catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public String initTezhengd(){
		String fieldname = getRequest().getParameter("fieldname");
		String ishow = "0";
		Map<String,String> tezhengdMap = getTezhengdTypeName();
		String colNames = "";
		String colModel = "";
		if (fieldname!=null && !fieldname.equals("")){
			ishow = "1";
			String[] fds = fieldname.split(",");
			for(int i=0;i<fds.length;i++){
				colNames += ",'"+tezhengdMap.get(fds[i])+"'";
				colModel += ",{name:'item"+i+"',index:'item"+i+"', width:80}";
			}
			getRequest().setAttribute("colNames", colNames);
			getRequest().setAttribute("colModel", colModel);
		}
		getRequest().setAttribute("ishow", ishow);
		getRequest().setAttribute("fieldname", fieldname);
		return "initTezhengd";
	}
	
	public Map<String,String> getTezhengdTypeName(){
		Map<String,String> map = new HashMap<String,String>();
		map.put("1", "绝缘接头");
		map.put("2", "连头");
		map.put("3", "弯头");
		map.put("4", "变径");
		map.put("5", "标志桩");
		map.put("6", "标志钉");
		map.put("7", "钢塑转换");
		map.put("8", "凝水缸");
		map.put("9", "焊缝");
		map.put("10", "信息球");
		map.put("11", "其他");
		map.put("12", "其他");
		map.put("13", "阳极");
		map.put("14", "测试桩");
		map.put("15", "排流装置");
		map.put("16", "穿跨越");
		map.put("17", "套管");
		return map;
	}
	
	public void tongjiTezhengd(){
		try{
			String fieldname = StringUtil.encodingUrl(getRequest().getParameter("fieldname"));
			String gxids = getRequest().getParameter("gxids");
			Map<String,String> filterMap=getPagerMap();
			if(null!=fieldname && !"".equals(fieldname)){
				filterMap.put("fieldname", fieldname);
			}
			if(null!=gxids && !"".equals(gxids)){
				filterMap.put("gxids", gxids);
			}
			PageResult result= tongjiService.tongjiTezhengd(filterMap);
			String[] fds = fieldname.split(",");
			String[] viewArray = new String[fds.length+1];
			viewArray[0] = "guanxianbh";
			for(int i=0;i<fds.length;i++){
				viewArray[i+1] = "item"+i;
			}
			String str=getColumnJson(result,viewArray);
			HttpServletResponse response = ServletActionContext.getResponse();
			response.setContentType("application/XML,charset=GBK");
			response.setHeader("Charset", "GBK");
			response.setCharacterEncoding("GBK");
			response.setContentType("text/xml");
			PrintWriter out = getResponse().getWriter();
			out.print(str);
			}
			catch (Exception e) {
				e.printStackTrace();
			}
	}
	
	public void tongjiTezhengdexp(){
		try{
			String fieldname = StringUtil.encodingUrl(getRequest().getParameter("fieldname"));
			String gxids = getRequest().getParameter("gxids");
			Map<String,String> filterMap=getPagerMap();
			if(null!=fieldname && !"".equals(fieldname)){
				filterMap.put("fieldname", fieldname);
			}
			if(null!=gxids && !"".equals(gxids)){
				filterMap.put("gxids", gxids);
			}
			List lists = tongjiService.tongjiTezhengdexp(filterMap);
			String filename = PubMethod.GetTimerName();
			String fileName=filename+".xlsx";			
			String pathUrl = getRequest().getSession().getServletContext().getRealPath("");
			String sourcefilepath = pathUrl+"\\tongji\\expmodecol2.xlsx";
			String targetfilepath = pathUrl+"\\tongji\\temp\\"+fileName;
			File targetfile = new File(targetfilepath);
			if (targetfile.exists()){
				targetfile.deleteOnExit();
			} 
			PubMethod.copyFile(new File(sourcefilepath), new File(targetfilepath));
			ExcelTool et = new ExcelTool(targetfilepath);
			Map<String,String> tezhengdMap = getTezhengdTypeName();
			String[] fds = fieldname.split(",");
			et.SetCells(1, 1, "管线编号");
			for(int i=0;i<fds.length;i++){
				et.SetCells(1, i+2, tezhengdMap.get(fds[i]));
			}
			int listsize = lists.size();
			et.InsertRowsAndCopy(1, 2, listsize-1);
			for(int i=0;i<listsize;i++){
				Object[] objs = (Object[])lists.get(i);
				et.SetCells(i+2, 1, objs[0].toString());
				for(int j=0;j<fds.length;j++){
					et.SetCells(i+2, j+2, objs[j+1].toString());
				}
			}
			et.Save();
			PubMethod.exportFile(targetfilepath,getResponse());
			targetfile = new File(targetfilepath);
			if (targetfile.exists()){
				targetfile.deleteOnExit();
			} 
		}
		catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public String initLishisj(){
		String fieldname = getRequest().getParameter("fieldname");
		String ishow = "0";
		Map<String,String> lishisjMap = getLishisjTypeName();
		String colNames = "";
		String colModel = "";
		if (fieldname!=null && !fieldname.equals("")){
			ishow = "1";
			String[] fds = fieldname.split(",");
			for(int i=0;i<fds.length;i++){
				colNames += ",'"+lishisjMap.get(fds[i])+"'";
				colModel += ",{name:'item"+i+"',index:'item"+i+"', width:80}";
			}
			getRequest().setAttribute("colNames", colNames);
			getRequest().setAttribute("colModel", colModel);
		}
		getRequest().setAttribute("ishow", ishow);
		getRequest().setAttribute("fieldname", fieldname);
		return "initLishisj";
	}
	
	public Map<String,String> getLishisjTypeName(){
		Map<String,String> map = new HashMap<String,String>();
		map.put("1", "异常统计");
		map.put("2", "特殊段统计");
		map.put("3", "违章占压统计");
		map.put("4", "应急事件统计");
		map.put("5", "泄漏点统计");
		map.put("6", "生产作业统计");
		map.put("7", "带气作业机械预制件统计");
		return map;
	}
	
	public void tongjiLishisj(){
		try{
			String fieldname = StringUtil.encodingUrl(getRequest().getParameter("fieldname"));
			String gxids = getRequest().getParameter("gxids");
			Map<String,String> filterMap=getPagerMap();
			if(null!=fieldname && !"".equals(fieldname)){
				filterMap.put("fieldname", fieldname);
			}
			if(null!=gxids && !"".equals(gxids)){
				filterMap.put("gxids", gxids);
			}
			PageResult result= tongjiService.tongjiLishisj(filterMap);
			String[] fds = fieldname.split(",");
			String[] viewArray = new String[fds.length+1];
			viewArray[0] = "guanxianbh";
			for(int i=0;i<fds.length;i++){
				viewArray[i+1] = "item"+i;
			}
			String str=getColumnJson(result,viewArray);
			HttpServletResponse response = ServletActionContext.getResponse();
			response.setContentType("application/XML,charset=GBK");
			response.setHeader("Charset", "GBK");
			response.setCharacterEncoding("GBK");
			response.setContentType("text/xml");
			PrintWriter out = getResponse().getWriter();
			out.print(str);
			}
			catch (Exception e) {
				e.printStackTrace();
			}
	}
	
	public void tongjiLishisjexp(){
		try{
			String fieldname = StringUtil.encodingUrl(getRequest().getParameter("fieldname"));
			String gxids = getRequest().getParameter("gxids");
			Map<String,String> filterMap=getPagerMap();
			if(null!=fieldname && !"".equals(fieldname)){
				filterMap.put("fieldname", fieldname);
			}
			if(null!=gxids && !"".equals(gxids)){
				filterMap.put("gxids", gxids);
			}
			List lists = tongjiService.tongjiLishisjexp(filterMap);
			String filename = PubMethod.GetTimerName();
			String fileName=filename+".xlsx";			
			String pathUrl = getRequest().getSession().getServletContext().getRealPath("");
			String sourcefilepath = pathUrl+"\\tongji\\expmodecol2.xlsx";
			String targetfilepath = pathUrl+"\\tongji\\temp\\"+fileName;
			File targetfile = new File(targetfilepath);
			if (targetfile.exists()){
				targetfile.deleteOnExit();
			} 
			PubMethod.copyFile(new File(sourcefilepath), new File(targetfilepath));
			ExcelTool et = new ExcelTool(targetfilepath);
			Map<String,String> tezhengdMap = getTezhengdTypeName();
			String[] fds = fieldname.split(",");
			et.SetCells(1, 1, "管线编号");
			for(int i=0;i<fds.length;i++){
				et.SetCells(1, i+2, tezhengdMap.get(fds[i]));
			}
			int listsize = lists.size();
			et.InsertRowsAndCopy(1, 2, listsize-1);
			for(int i=0;i<listsize;i++){
				Object[] objs = (Object[])lists.get(i);
				et.SetCells(i+2, 1, objs[0].toString());
				for(int j=0;j<fds.length;j++){
					et.SetCells(i+2, j+2, objs[j+1].toString());
				}
			}
			et.Save();
			PubMethod.exportFile(targetfilepath,getResponse());
			targetfile = new File(targetfilepath);
			if (targetfile.exists()){
				targetfile.deleteOnExit();
			} 
		}
		catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public void tongjiDongtaisj(){
		try{
			String fieldname = StringUtil.encodingUrl(getRequest().getParameter("fieldname"));
			String gxids = getRequest().getParameter("gxids");
			Map<String,String> filterMap=getPagerMap();
			if(null!=fieldname && !"".equals(fieldname)){
				filterMap.put("fieldname", fieldname);
			}
			if(null!=gxids && !"".equals(gxids)){
				filterMap.put("gxids", gxids);
			}
			PageResult result= tongjiService.tongjiDongtaisj(filterMap);
			String[] viewArray={"tongjixm","guanxianbh","heji"};
			String str=getColumnJson(result,viewArray);
			HttpServletResponse response = ServletActionContext.getResponse();
			response.setContentType("application/XML,charset=GBK");
			response.setHeader("Charset", "GBK");
			response.setCharacterEncoding("GBK");
			response.setContentType("text/xml");
			PrintWriter out = getResponse().getWriter();
			out.print(str);
			}
			catch (Exception e) {
				e.printStackTrace();
			}
	}
	
	public void tongjiDongtaisjpic(){
		try{
			String fieldname = StringUtil.encodingUrl(getRequest().getParameter("fieldname"));
			String gxids = getRequest().getParameter("gxids");
			Map<String,String> filterMap=getPagerMap();
			if(null!=fieldname && !"".equals(fieldname)){
				filterMap.put("fieldname", fieldname);
			}
			if(null!=gxids && !"".equals(gxids)){
				filterMap.put("gxids", gxids);
			}
			List lists = tongjiService.tongjiDongtaisjpic(filterMap);
			JSONObject root = new JSONObject();
			JSONArray jsonArray = new JSONArray();
			List<String> strList = new ArrayList<String>();
			for(int i=0;i<lists.size();i++){
				Object[] objs = (Object[])lists.get(i);
				JSONObject obsjson = new JSONObject();
				String labelname = objs[0]==null?"":objs[0].toString();
				obsjson.put("name", labelname);
				obsjson.put("value", objs[2]==null?"":objs[2].toString());
				jsonArray.add(obsjson);
				strList.add(labelname);
			}
			root.put("list", jsonArray);
			root.put("label", strList);
			PrintWriter out = com.tjtt.tdm.base.PubMethod.GetPrintWriter();
			out.print(root);
			}
			catch (Exception e) {
				e.printStackTrace();
			}
	}
	
	public void tongjiDongtaisjexp(){
		try{
			String fieldname = StringUtil.encodingUrl(getRequest().getParameter("fieldname"));
			String gxids = getRequest().getParameter("gxids");
			Map<String,String> filterMap=getPagerMap();
			if(null!=fieldname && !"".equals(fieldname)){
				filterMap.put("fieldname", fieldname);
			}
			if(null!=gxids && !"".equals(gxids)){
				filterMap.put("gxids", gxids);
			}
			List lists = tongjiService.tongjiDongtaisjpic(filterMap);
			String filename = PubMethod.GetTimerName();
			String fileName=filename+".xlsx";			
			String pathUrl = getRequest().getSession().getServletContext().getRealPath("");
			String sourcefilepath = pathUrl+"\\tongji\\expmode.xlsx";
			String targetfilepath = pathUrl+"\\tongji\\temp\\"+fileName;
			File targetfile = new File(targetfilepath);
			if (targetfile.exists()){
				targetfile.deleteOnExit();
			} 
			PubMethod.copyFile(new File(sourcefilepath), new File(targetfilepath));
			ExcelTool et = new ExcelTool(targetfilepath);
			int listsize = lists.size();
			et.InsertRowsAndCopy(1, 2, listsize-1);
			for(int i=0;i<listsize;i++){
				Object[] objs = (Object[])lists.get(i);
				et.SetCells(i+2, 1, objs[0].toString());
				et.SetCells(i+2, 2, objs[1].toString());
				et.SetCells(i+2, 3, objs[2].toString());
			}
			et.Save();
			PubMethod.exportFile(targetfilepath,getResponse());
			targetfile = new File(targetfilepath);
			if (targetfile.exists()){
				targetfile.deleteOnExit();
			} 
		}
		catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public void createDanxiant(){
		try{
			String gxids = getRequest().getParameter("gxids");
			Map<String,String> filterMap=getPagerMap();
			if(null!=gxids && !"".equals(gxids)){
				filterMap.put("gxids", gxids);
			}
			String strWhere = "";
			if (filterMap.get("gxids")!=null){
				gxids = filterMap.get("gxids").toString().replace("gx", "");
			}
			if (!gxids.equals("")){
				String stridsinfo = "";
				String[] arraygxids = gxids.split(",");
				for(int i=0;i<arraygxids.length;i++){
					if (!arraygxids[i].equals(""))
					{
						stridsinfo+="'"+arraygxids[i]+"',";
					}
				}
				if (stridsinfo.length()>0){
					stridsinfo = stridsinfo.substring(0,stridsinfo.length()-1);
				}
				strWhere = " and pipelineno in ("+stridsinfo+")";
			}
			//画管段,管段节点
			String strSql = "select t.beginnodey,t.beginnodex,t.endnodey,t.endnodex from " +
					"PTEM_PIPESECTION t where 1=1 "+strWhere;
			List guanduanList = dbService.queryDataBySql(strSql);
			//画管线
			strSql = "select t.node1y-1.5,t.node1x+1.5,t.node1y+1.5,t.node1x-1.5,t.node1y+1.5,t.node1x+1.5,t.node1y-1.5,t.node1x-1.5," +
					"t.node2y-1.5,t.node2x+1.5,t.node2y+1.5,t.node2x-1.5,t.node2y+1.5,t.node2x+1.5,t.node2y-1.5,t.node2x-1.5,t.node3y+3," +
					"t.node3x+120,PIPELINENO from ptem_pipeline t where node1y is not null and node1x is not null "+strWhere;
			List guanxianList = dbService.queryDataBySql(strSql);
			//画闸门
//			strSql = "select t.locationy-1.5,t.locationx+1.5,t.locationy+1.5,t.locationx-1," +
//					"t.locationy+1.5,t.locationx+1,t.locationy-1.5,t.locationx-1,t.locationy+3,t.locationx+120,VALVEPITNO " +
//					"from PTEM_VALVE t where 1=1 "+strWhere;
			
			strSql = "select t.locationy-1.5,t.locationx+1,t.locationy+1.5,t.locationx-1," +
			"t.locationy+1.5,t.locationx+1,t.locationy-1.5,t.locationx-1,t.locationy+3,t.locationx+3,VALVENAME " +	
			"from PTEM_VALVE t where 1=1 "+strWhere;
			
			List zhamenList = dbService.queryDataBySql(strSql);
			//画站箱
//			strSql = "select LOCATIONY-1,LOCATIONX+1,LOCATIONY+1,LOCATIONX-1,LOCATIONY+3," +
//					"LOCATIONX+120,STATIONNAME  from PTEM_STATION t where 1=1 "+strWhere;
			
			strSql = "select LOCATIONY-1,LOCATIONX+1,LOCATIONY+1,LOCATIONX-1,LOCATIONY+3," +
			"LOCATIONX+3,STATIONNAME  from PTEM_STATION t where 1=1 "+strWhere;
	
			
			List zhanxiangList = dbService.queryDataBySql(strSql);
			
			String filename = PubMethod.GetTimerName();
			String pathUrl = getRequest().getSession().getServletContext().getRealPath("");
			String targetfilepath = pathUrl+"\\tongji\\temp\\"+filename+".txt";
			File file = new File(targetfilepath);
			file.createNewFile();
			PrintWriter out = new PrintWriter(file);
			for(int i=0;i<guanduanList.size();i++){
				Object[] objs = (Object[])guanduanList.get(i);
				out.println("pl "+objs[0]+","+objs[1]+" "+objs[2]+","+objs[3]+" c");
				out.println("circle "+objs[0]+","+objs[1]+" 0.5");
				out.println("circle "+objs[2]+","+objs[3]+" 0.5");
			}
			
			for(int i=0;i<guanxianList.size();i++){
				Object[] objs = (Object[])guanxianList.get(i);
				out.println("pl "+objs[0]+","+objs[1]+" "+objs[2]+","+objs[3]+" c " +
						"pl "+objs[4]+","+objs[5]+" "+objs[6]+","+objs[7]+" c");
				out.println("text j ml "+objs[8]+","+objs[9]+" "+objs[10]+"");
			}
			
			for(int i=0;i<zhamenList.size();i++){
				Object[] objs = (Object[])zhamenList.get(i);
				out.println("pl "+objs[0]+","+objs[1]+" "+objs[2]+","+objs[3]+" "+objs[4]+","+objs[5]+" "+objs[6]+","+objs[7]+" c");
				//out.println("text j ml "+objs[8]+","+objs[9]+" "+objs[10]+"");
				out.println("-text j ml "+objs[8]+","+objs[9]+" "+"5 0 "+objs[10]+"");
			}
			
			for(int i=0;i<zhanxiangList.size();i++){
				Object[] objs = (Object[])zhanxiangList.get(i);
				out.println("rectangle "+objs[0]+","+objs[1]+" "+objs[2]+","+objs[3]+"");
				//out.println("text j ml "+objs[4]+","+objs[5]+" "+objs[6]+"");
				out.println("-text j ml "+objs[4]+","+objs[5]+" "+"5 0 "+objs[6]+"");
			}
			
			out.flush();
			out.close();
			PubMethod.exportFile(targetfilepath,getResponse());
			File targetfile = new File(targetfilepath);
			if (targetfile.exists()){
				targetfile.deleteOnExit();
			} 
		}
		catch (Exception e) {
			e.printStackTrace();
		}
	}
	
}
